package com.naivecoders.refex;

import java.util.Arrays;

import com.naivecoders.refex.functions.FCode;

public class FName {

    private final FCode[] name;

    public FName(FCode... name) {
        super();
        this.name = name;
        if (name.length < 1) {
            throw new IllegalArgumentException();
        }
    }

    public FName(FCode name) {
        super();
        this.name = new FCode[]{name};
    }

    public FCode[] asArray() {
        return name;
    }

    public boolean isElementary() {
        return name.length == 1;
    }

    public FCode asElementary() {
        return name[0];
    }

    public boolean isArgument() {
        return name[0] == FCode.G;
    }

    @Override
    public String toString() {
        return Utils.asString(name);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + Arrays.hashCode(name);
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        FName other = (FName) obj;
        if (!Arrays.equals(name, other.name)) {
            return false;
        }
        return true;
    }
}
